package top.ytazwc.take.redis.cluster;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * @author 花木凋零成兰
 * @title EGM
 * @date 2024/4/28 15:40
 * @package top.ytazwc.take.redis.cluster
 * @description 模拟Redis缓存服务 EGM集群
 */
@Slf4j
public class EGM {

    private Map<String, String> dataMap = new ConcurrentHashMap<>();
    // 获取数据
    public String gain(String key) {
        log.info("EGM获取数据 key:{}", key);
        return dataMap.get(key);
    }
    // 写入数据
    public void set(String key, String value) {
        log.info("EGM写数据 key:{}, val:{}", key, value);
        dataMap.put(key, value);
    }
    // 写入数据 存在有效时间
    public void setEx(String key, String value, long timeout, TimeUnit timeUnit) {
        log.info("EGM写入数据 key:{}, val:{}, timeout:{}, timeUnit:{}", key, value, timeout, timeUnit);
        dataMap.put(key, value);
    }
    // 删除数据
    public void delete(String key) {
        log.info("EGM删除数据 key: {}", key);
        dataMap.remove(key);
    }

}
